<% problem_cis = @deployment.rfc_cis.select {|ci| ci.comments.present? && ci.dpmtRecordState == 'failed'} %>
<% if problem_cis.present? || @deployment.description.present? %>
  <% if @deployment.description.present? %>
    <div><%= @deployment.description %></div>
  <% end %>
  <% max_count = 3
     max_length = 200 %>
  <div class="alert alert-danger deployment-problems">
    <% problem_cis[0..max_count - 1].each do |ci| %>
      <% text = ci.comments %>
      <div>
        <% if text.size > max_length %>
          <%= text[0..max_length - 1] %><%= link_to_function(content_tag(:b, '...'), '$j(this).hide().siblings("span").toggle(300)') %><span class="hide"><%= text[max_length..-1] %></span>
        <% else %>
          <%= text %>
        <% end %>
        &nbsp;&nbsp;&nbsp;<%= link_to(icon('external-link', 'Log'), log_data_assembly_transition_environment_deployment_path(@assembly, @environment, @deployment, :rfcId => ci.rfcId), :target => '_blank') %>
      </div>
    <% end %>
    <% if problem_cis.size > max_count %>
      <%= link_to_function(content_tag(:b, '...'), '$j(this).hide().next().toggle(300)') %>
      <div class="hide">
        <% problem_cis[max_count..-1].each do |ci| %>
          <% text = ci.comments %>
          <div>
            <% if text.size > max_length %>
              <%= text[0..max_length - 1] %><%= link_to_function(content_tag(:b, '...'), '$j(this).hide().siblings("span").toggle(300)') %><span class="hide"><%= text[max_length..-1] %></span>
            <% else %>
              <%= text %>
            <% end %>
            &nbsp;&nbsp;&nbsp;<%= link_to(icon('external-link', 'Log'), log_data_assembly_transition_environment_deployment_path(@assembly, @environment, @deployment, :rfcId => ci.rfcId), :target => '_blank') %>
          </div>
        <% end %>
      </div>
    <% end %>
  </div>
<% end %>
